package org.gruposp2p.proyectokarma.gwt.client.util;

import com.google.gwt.dom.client.Element;

public class Browser {

	public static boolean isChrome () {
		return (getUserAgent().indexOf("chrome") > - 1);
	}
	
	public static native String getUserAgent() /*-{
		return navigator.userAgent.toLowerCase();
	}-*/;
	
    /**
     * Evaluate scripts in an HTML string. Will eval both <script src=""></script>
     * and <script>javascript here</scripts>.
     * 
     * http://snippets.dzone.com/posts/show/7052
     *
     * @param element a new HTML(text).getElement()
     */
    public static native void evalScripts(Element element) /*-{
        var scripts = element.getElementsByTagName("script");
    
        for (i=0; i < scripts.length; i++) {
            // if src, eval it, otherwise eval the body
            if (scripts[i].hasAttribute("src")) {
                var src = scripts[i].getAttribute("src");
                var script = $doc.createElement('script');
                script.setAttribute("src", src);
                $doc.getElementsByTagName('body')[0].appendChild(script);
            } else {
                $wnd.eval(scripts[i].innerHTML);
            }
        }
    }-*/;

}
